package com.zhuiyuan.coupon.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import com.zhuiyuan.common.utils.PageUtils;
import com.zhuiyuan.common.utils.R;
import com.zhuiyuan.coupon.entity.SmsCouponEntity;
import com.zhuiyuan.coupon.service.SmsCouponService;

/**
 * 优惠券信息
 *
 * @author hulian
 * @email hulian425@gmail.com
 * @date 2021-09-05 18:28:54
 */
@RestController
@RequestMapping("coupon/smscoupon")
@RefreshScope
public class SmsCouponController {

    @Autowired
    private SmsCouponService smsCouponService;

     @Value("${coupon.user.name}")
    private String           name;
     @Value("${coupon.user.age}")
    private Integer          age;

    @RequestMapping("/test")
    public R test() {

        return R.ok().put("name", name).put("age", age);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = smsCouponService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/member/list")
    public R membercoupons() {
        SmsCouponEntity couponEntity = new SmsCouponEntity();
        couponEntity.setCouponName("满100减10");
        return R.ok().put("coupons", Arrays.asList(couponEntity));
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SmsCouponEntity smsCoupon = smsCouponService.getById(id);

        return R.ok().put("smsCoupon", smsCoupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SmsCouponEntity smsCoupon) {
        smsCouponService.save(smsCoupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SmsCouponEntity smsCoupon) {
        smsCouponService.updateById(smsCoupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        smsCouponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
